/*
 * @Description: 拆分案卷弹窗
 * @Author: Rfan
 * @Date: 2022-07-18 15:02:39
 * @LastEditTime: 2022-07-18 16:02:39
 */

import { Button, message, Modal } from 'antd';
import { useLevelTableContext } from '@/components/LevelTable/contexts/LevelTableContext';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import { addPendingDisposition } from '@/api/archives/disposition';
import type { FC } from 'react';

interface IAddAppraisalBtnProps {}

const AddAppraisalBtn: FC<IAddAppraisalBtnProps> = (props) => {
  const { baseInfo, selectItems } = useLevelTableContext();

  const addAppraisalMethod = () => {
    const params = {
      archiveTypeId: baseInfo.archiveTypeId,
      dataSources: 0,
      entryId: selectItems[0]
    };
    Modal.confirm({
      title: '加入鉴定',
      content: '是否将选中的档案加入鉴定？',
      icon: <ExclamationCircleOutlined />,
      onOk() {
        addPendingDisposition(params).then(() => {
          message.success('加入鉴定成功');
        });
      },
      onCancel() {
        console.log('Cancel');
      }
    });
  };

  return (
    <>
      <Button
        disabled={selectItems.length !== 1}
        onClick={() => {
          addAppraisalMethod();
        }}
      >
        加入鉴定
      </Button>
    </>
  );
};

export default AddAppraisalBtn;
